Tool
Type Parameters
Application-defined input type, must be @Serializable. The model produces JSON matching its schema; the agent deserializes via inputSerializer before calling executor.
Application-defined output type, must be @Serializable. Serialized into the model's tool-result message via outputSerializer, or summarized via toModelOutput if the raw output would be too verbose for the model.
Caller-supplied typed context propagated through the whole loop (set via callOptionsSchema, accessed inside the executor as this.context).
The internal executor always returns a Flow (the v6 alignment per tool.ts:68-71's AsyncIterable<OUTPUT> shape). Single-value tools built via tool wrap their suspend (TInput) -> TOutput body in a one-emission flow; streaming tools built via streamingTool pass their Flow body straight through. The agent loop's tool dispatcher collects with one-step lookahead — non-final emissions become StreamEvent.ToolResult(preliminary = true), the last emission is the final result that lands in the model's message log.